package com.elm.food.controller;
import com.elm.common.pojo.Result;
import com.elm.food.pojo.Food;
import com.elm.food.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/food")
public class FoodController {
    @Autowired
    private FoodService foodService;

    @GetMapping("/listByBusinessId")
    public Result<List<Food>> listFoodByBusinessId(@RequestParam Integer businessId){
        List<Food> list=foodService.listFoodByBusinessId(businessId);
        if(list.size()!=0){
            return Result.success(list);
        }
        return Result.error("不存在该食品");
    }

    @GetMapping("/findByFoodId")
    public Result<Food> findFoodByFoodId(@RequestParam Integer foodId){
        Food food=foodService.findFoodByFoodId(foodId);
        if (food!=null){
            return Result.success(food);
        }

        return Result.error("不存在该食品");
    }
}
